

let userId_const = localStorage.getItem("userId");
let userName_const = localStorage.getItem("userName");

let username = $(".dropdown-user-name");
username.find('i').remove();
let user_name = '<i>你好，'+userName_const+'老师</i>';
username.append(user_name);                       //生成导航栏的老师名字
username = $("#user_name");
username.find('span').remove();
user_name = '<span>'+userName_const+'老师</span>'      //生成导航栏下拉框的老师名字
username.append(user_name);

$(document).ready(function() {
    console.log(userId_const);
    $("#submitPwd").click(function () {
        let userOldPwd = $("#inputOldPwd").val();
        let userNewPwd = $("#inputNewPwd").val();
        $.ajax({
            url: '/user/login',
            type: 'get',
            dataType: 'json',
            async: false,
            data: {"userId": userId_const, "userPwd": userOldPwd},
            success: function (data) {
                console.log(data);
                if(data.length!=0){
                $.ajax({
                    url: '/user/upDateUserPwd',
                    type: 'post',
                    dataType: 'json',
                    async: false,
                    data: {"userId": userId_const, "userPwd": userNewPwd},
                    success: function () {
                        swal({
                                title: "密码修改成功!",
                                text: "请重新登录！",
                                type: "success",
                                confirmButtonColor: "#2a67ec",
                                confirmButtonText: "重新登陆！"
                            },
                            function (isConfirm) {
                                if (isConfirm) {
                                    window.location.href = "../web/login.html";
                                }
                            });
                    }

                });
                }else {
                    swal({title: "旧密码输入不正确，请重新输入",type: "error"});
                }
            },
            error:function (){
                swal({title: "旧密码输入不正确，请重新输入",type: "error"});
            }
        });

    })

})
